package eureka.provider.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 服务发现
 */
@RestController
public class ProviderEurekaController {
    @Autowired
    private DiscoveryClient discoveryClient;

    @GetMapping("/provider/discovery")
    public Object discovery(){
        //查询出eureka中存在的所有微服务
        List<String> serviceList = discoveryClient.getServices();
        //通过微服务名称查询指定微服务
        List<ServiceInstance> instances = discoveryClient.getInstances("eureka-provider");
        return this.discoveryClient;
    }
}
